package com.ruoyi.business.service.impl;

import com.ruoyi.business.service.StatisticsService;
import com.ruoyi.business.domain.BusCbsgrxx;
import com.ruoyi.business.domain.statistics.StatisticsIntBO;
import com.ruoyi.business.domain.vo.BusCbsgrxxSaveVO;
import com.ruoyi.business.mapper.BusCbsgrxxMapper;
import com.ruoyi.business.service.IBusCbsgrxxService;
import com.ruoyi.business.utils.BusOperatorUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 承包商工人信息Service业务层处理
 *
 * @author yaowei
 * @date 2021-06-30
 */
@Service
public class BusCbsgrxxServiceImpl implements IBusCbsgrxxService {

    @Autowired
    private BusCbsgrxxMapper busCbsgrxxMapper;

    @Autowired
    private StatisticsIntService statisticsService;

    /**
     * 查询承包商工人信息
     *
     * @param id 承包商工人信息ID
     * @return 承包商工人信息
     */
    @Override
    public BusCbsgrxx selectBusCbsgrxxById(Long id) {
        return busCbsgrxxMapper.selectBusCbsgrxxById(id);
    }

    /**
     * 查询承包商工人信息列表
     *
     * @param busCbsgrxx 承包商工人信息
     * @return 承包商工人信息
     */
    @Override
    public List<BusCbsgrxx> selectBusCbsgrxxList(BusCbsgrxx busCbsgrxx) {
        return busCbsgrxxMapper.selectBusCbsgrxxList(busCbsgrxx);
    }

    @Override
    public List<StatisticsIntBO> gzztStatistics(Long cbsId) {
        List<StatisticsIntBO> gzztList = busCbsgrxxMapper.gzztStatistics(cbsId);
        return statisticsService.getStatisticsByDictType(DICT_TYPE_GR_GZZT, gzztList);
    }

    @Override
    public List<StatisticsIntBO> gwStatistics(Long cbsId) {
        List<StatisticsIntBO> gwList = busCbsgrxxMapper.gwStatistics(cbsId);
        return statisticsService.getStatisticsByDictType(DICT_TYPE_GR_GW, gwList);
    }

    /**
     * 新增承包商工人信息
     *
     * @param busCbsgrxxSaveVO 承包商工人信息
     * @return 结果
     */
    @Override
    public int insertBusCbsgrxx(BusCbsgrxxSaveVO busCbsgrxxSaveVO) {
        BusCbsgrxx busCbsgrxx = BeanUtils.copyBean(busCbsgrxxSaveVO, new BusCbsgrxx());
        BusOperatorUtils.setOperator(busCbsgrxx);
        return busCbsgrxxMapper.insertBusCbsgrxx(busCbsgrxx);
    }

    /**
     * 修改承包商工人信息
     *
     * @param busCbsgrxxSaveVO 承包商工人信息
     * @return 结果
     */
    @Override
    public int updateBusCbsgrxx(BusCbsgrxxSaveVO busCbsgrxxSaveVO) {
        Long id = busCbsgrxxSaveVO.getId();
        BusCbsgrxx busCbsgrxx = busCbsgrxxMapper.selectBusCbsgrxxById(id);
        BeanUtils.copyBean(busCbsgrxxSaveVO, busCbsgrxx);
        BusOperatorUtils.setOperator(busCbsgrxx);
        return busCbsgrxxMapper.updateBusCbsgrxx(busCbsgrxx);
    }

    /**
     * 批量删除承包商工人信息
     *
     * @param ids 需要删除的承包商工人信息ID
     * @return 结果
     */
    @Override
    public int deleteBusCbsgrxxByIds(Long[] ids) {
        return busCbsgrxxMapper.deleteBusCbsgrxxByIds(ids);
    }

    /**
     * 删除承包商工人信息信息
     *
     * @param id 承包商工人信息ID
     * @return 结果
     */
    @Override
    public int deleteBusCbsgrxxById(Long id) {
        return busCbsgrxxMapper.deleteBusCbsgrxxById(id);
    }

    /**
     * 统计在职人员数量
     *
     * @return
     */
    @Override
    public Long countAll() {
        return busCbsgrxxMapper.countAll();
    }
}
